package com.example.cymjoe.huaweishopping.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.cymjoe.huaweishopping.R;
import com.example.cymjoe.huaweishopping.bean.SYGridBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by cymjoe on 2016/12/6.
 */
public class SYGVAdapter extends BaseAdapter {
    private Context context;
    private List<SYGridBean.DataBean.NewRegionListBean.RegionContentBean.ProductListBean> data;

    public SYGVAdapter(Context context, List<SYGridBean.DataBean.NewRegionListBean.RegionContentBean.ProductListBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data!=null? data.size():0;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
//jjj
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.shouyegridview_item, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.t1 = (TextView) convertView.findViewById(R.id.prdName);
            viewHolder.t2 = (TextView) convertView.findViewById(R.id.prdDescription);
            viewHolder.t3 = (TextView) convertView.findViewById(R.id.prdUnitPrice);
            viewHolder.img = (ImageView) convertView.findViewById(R.id.img);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        SYGridBean.DataBean.NewRegionListBean.RegionContentBean.ProductListBean bean = data.get(position);
        if (bean != null) {

            viewHolder.t1.setText(bean.getPrdName());
            viewHolder.t2.setText(bean.getPrdDescription());
            viewHolder.t3.setText("￥"+bean.getPrdUnitPrice());
            Picasso.with(context).load(bean.getPrdPicUrl()).error(R.mipmap.ic_launcher).placeholder(R.mipmap.ic_launcher).into(viewHolder.img);

        }
        return convertView;
    }

    class ViewHolder {
        TextView t1, t2, t3;
        ImageView img;

    }
}
